#include "singleton.h"
#include <iostream>
#include <thread>
#include <vector>
#include <future>

class Test final : public Singleton<Test>
{
    friend class Singleton<Test>;
    private:
        Test() = default;
        virtual ~Test() = default;
        Test(const Test&) = delete;
        Test& operator= (const Test&) = delete;

    public:
        void desc()
        {
            std::cout << "Test对象地址:" << this;
        }
};

int main()
{
    std::mutex mtx;

    std::vector<std::future<void>>  workers;
    for (int i = 0; i != 10; i++)
    {
        workers.push_back(std::async(std::launch::async, [&mtx]()->void{
            std::this_thread::yield();
            std::lock_guard<std::mutex> lck(mtx);
            std::cout << "线程ID:" << std::this_thread::get_id() << " ";
            Test::GetInstance()->desc();
            std::cout << std::endl;
        }));
    }

    for (auto& work : workers)
    {
        work.get();
    }
    return 0;
}
